# -*- coding: iso-8859-1 -*-


"""
Hexagone class - contains everything usefull to manage hexs

Catanyste - Copyright 2008-2009 Julien RAIGNEAU
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance 
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
the specific language governing permissions and limitations under the License. 

@author J.Raigneau
"""

from gamecomponents import GameComponents

class Hexagone(object):
    """
    Manages hexagones
    """
    DESERT = GameComponents.DESERT
    LUMBER = GameComponents.LUMBER
    GRAIN = GameComponents.GRAIN
    BRICK = GameComponents.BRICK
    ORE = GameComponents.ORE
    WOOL = GameComponents.WOOL
    SEA = GameComponents.WATER
    PORT3 = GameComponents.PORT3
    PORT2LUMBER = GameComponents.PORT2LUMBER
    PORT2BRICK = GameComponents.PORT2BRICK
    PORT2WOOL = GameComponents.PORT2WOOL
    PORT2GRAIN = GameComponents.PORT2GRAIN
    PORT2ORE = GameComponents.PORT2ORE
    DEFAULT = "nada"
    
    """
    wool, grain, brick, ore, lumber
    mouton, ble, argile, minerai, mouton
    """    

    def __init__(self, board, (u,v), resource=DEFAULT, value=99):
        """
        Inits hex class
        """
        self.board = board
        self.uv = (int(u),int(v)) # coordonnees sur la grille
        self.resource = resource
        self.value = value
        self.hasthief = 0
    
    def set_resource(self, resource):
        self.resource = resource
        
    def get_resource(self):
        return self.resource
    
    def set_value(self, value):
#        if self.resource != self.SEA:
        self.value = value

    def get_value(self):
        return self.value

    def PrintClass(self):
        print "%s en (%s,%s) avec la valeur %s et les noeuds {%d,%d,%d,%d,%d,%d}" % (self.resource, self.uv[0], self.uv[1], self.value, self.noeuds[0], self.noeuds[1], self.noeuds[2], self.noeuds[3], self.noeuds[4], self.noeuds[5])

class Thief(object):
    """
    Manages thief
    """
    hex = None
    def __init__(self, uv):
        self.uv = uv
        
    def getCoord(self):
        """
        returns thief coordinates
        """
        return self.uv
    
    def setThief(self, hex):
        if self.hex: #old hex => False so we don't have 2 thieves !
            self.hex.hasthief = False
        self.hex = hex
        self.hex.hasthief = True
        self.uv=hex.uv


        
